<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/webuploader/webuploader.css" />

    <title>添加房源属性 - 房源属性管理 - H-ui.admin v3.1</title>
</head>
<body>
<article class="page-container">
    {{-- 表单验证提示 --}}

    <form  class="form form-horizontal" action="{{ route('admin.fangattr.store') }}" method="post" id="form-admin-add">
        @include('admin.common.validate')
        {{ csrf_field() }}

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">是否顶级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    <select class="select" name="pid"  size="1">
                        <option value="0">==顶级==</option>
                        @foreach($data as $val)
                            <option value="{{ $val->id }}">{{ $val->name }}</option>
                        @endforeach
                    </select>
			    </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>属性名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" name="name"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">* </span>属性图标：</label>
            <div class="formControls col-xs-4 col-sm-5">
                <!-- 表单提交时的封面地址 -->
                <input type="hidden" name="icon" id="icon" value="{{ config('up.pic') }}">
                <div id="picker">选择图标</div>
            </div>
            <div class="formControls col-xs-4 col-sm-4">
                <img src="" id="img" style="width: 50px;">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>字段名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder=""  name="field_name">
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;添加属性&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/webuploader/webuploader.js"></script>
<script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        //文件上传
        var uploader = WebUploader.create({
            //自动上传
            auto:true,
            //swf路径
            swf:'/webuploader/uploader.swf',
            server:'{{ route('admin.fangattr.upfile') }}',
            formData:{
                _token:'{{ csrf_token() }}'
            },
            //文件表单名称
            fileVal:'file',
            pick:{
                id:'#picker',
                //是否上传多个
                multiple:false
            },
            //压缩
            resize:true
        });
        //上传成功回调
        uploader.on('uploadSuccess',function(file,ret){
            //图片路径
            let src = ret.url;
            //给表单添加值
            $('#icon').val(src);
            //显示图片
            $('#img').attr('src',src);
        });

        $("#form-admin-add").validate({
            rules:{
                name:{
                    required:true,
                    maxlength:30
                },
                field_name:{
                    maxlength:40
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler: function (form) {
                // 表单提交地址
                let url = $(form).attr('action');
                // 表单序列化   _token=aaa&name=fewflew
                let data = $(form).serialize();

                // jquery post提交
                $.post(url,data).then(({status,msg})=>{
                    if(status == 0){
                        layer.msg(msg,{icon:1,time:2000},()=>{
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.$('.btn-refresh').click();
                            parent.layer.close(index);
                        })
                    }else{
                        layer.msg(msg,{icon:2,time:2000})
                    }

                })
            }
        });
    });

    // var index = parent.layer.getFrameIndex(window.name);
    // parent.$('.btn-refresh').click();
    // // parent.layer.close(index);
</script>
</body>
</html>